#!/usr/bin/env perl

use strict;
use warnings;

BEGIN {
	push @::INC,'../libs' if -d '../libs';
	push @::INC,'libs' if -d 'libs';
}

use gri_frontend;

$::f=undef;
$::f='../globals_config.xml' if -e '../globals_config.xml';
$::f='globals_config.xml' if -e 'globals_config.xml';

if(! $::f) {
	print STDERR "Error: Failed to find 'globals_config.xml' file.\n";
	exit 1;
}

# Load in the configuration file ...

my $ff=new gri_frontend($::f);
if(! $ff) {
	print STDERR "Error: Failed to load in frontend.\n";
	exit 1;
}


{
	my $username; my $password;
	print "Enter username: "; $username=<STDIN>; chomp $username;
	print "Enter password: "; $password=<STDIN>; chomp $password;
	$password='{HEX}'.unpack('h*',$password);
	my ($a,$b)=$ff->send_authd_request("IS_VALID  U=$username P=$password\n");
	if(!$a) {
		print STDERR "authd_query error: $_\n" foreach(@$b);
		exit 1;
	}
	print "Result: $b\n";
	exit 0;
}
